const pkg = require('./package')

module.exports = {
  mode: 'universal',
  env: {
    baseUrl: process.env.BASE_URL || 'http://127.0.0.1:8080'
  },
  /*
  ** Headers of the page
  */
  head: {
    title: '数据魔方',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: pkg.description }
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
  },

  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#538efe' },

  /*
  ** Global CSS
  */
  css: ['element-ui/lib/theme-chalk/index.css', '@/static/css/common.css'],

  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    '@/plugins/element-ui',
    '@/plugins/vue-lazyload',
    '@/plugins/vue-quevo',
    '@/plugins/vue-qs'
  ],

  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios'
  ],
  /*
  ** Axios module configuration
  */
  axios: {
    // See https://github.com/nuxt-community/axios-module#options
    // baseURL: pkg.isDev ? '' : '//prod.ezaction.cn/',
    // baseURL: '',
    proxy: true,
    retry: 3
    // browserBaseURL: 'http://127.0.0.1:8083'
  },
  proxy: {
    '/v3': {
      target: 'http://127.0.0.1:8083/',
      changeOrigin: true,
      pathRewrite: { '^/v3': '' }
    },
    '/captcha': {
      target: 'http://127.0.0.1:8083',
      changeOrigin: true
    },
    '/protect': {
      target: 'http://127.0.0.1:8083',
      changeOrigin: true
    }
  },
  /*
  ** Build configuration
  */
  build: {
    transpile: [/^element-ui/],
    /* vendors: [
      'vuex',
      'element-ui',
      'vue-lazyload',
      'vue-quevo',
      'axios',
      'vue-qs'
    ], */
    /*
    ** You can extend webpack config here
    */
    extend(config, ctx) {
      // Run ESLint on save
      if (ctx.isDev && ctx.isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    },
    router: {
      extendRoutes(routes, resolve) {
        routes.push({
          name: 'custom',
          path: '*',
          component: resolve(__dirname, 'pages/404.vue')
        })
      }
    }
  }
}
